package com.wnxy.pawnbackgroundsystem.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wnxy.pawnbackgroundsystem.entity.Identify;
import com.wnxy.pawnbackgroundsystem.param.goodsParam.GoodsParam;
import com.wnxy.pawnbackgroundsystem.param.identifyParam.GetIdentify;
import com.wnxy.pawnbackgroundsystem.param.identifyParam.IdentifyParam;
import com.wnxy.pawnbackgroundsystem.response.Result;
import com.wnxy.pawnbackgroundsystem.service.IIdentifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 鉴定历史表 前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2021-10-17
 */
@RestController
@RequestMapping("/identify")
@Slf4j
@CrossOrigin("*")
public class IdentifyController {

    @Resource
    private IIdentifyService identifyService;

    @GetMapping("queryAllIdentify")
    public Result queryAllGoods(GoodsParam goodsParam,
             @RequestParam(name = "pageSize",defaultValue = "10") int pageSize
            , @RequestParam(name = "current",defaultValue = "1") int current){
        log.info("查询历史鉴定控制层：查询所有商品信息 参数={},{},{}",goodsParam.getGoodsId(),pageSize,current);
        IPage byPage = identifyService.findAllidentifyByPage( goodsParam.getGoodsId(),pageSize, current);
        log.info("查询历史鉴定控制层,返回前端的参数bypage:{}",byPage.getRecords());
//        if(byPage!=null) {
//            return Result.success(Identify.class,byPage);
//        }
//        return Result.fail("500","查询为空");
        return Result.success(Identify.class,byPage);
    }

    @PostMapping("identifyTure")
    public Result identifyTure(@RequestBody GetIdentify getIdentify){
        log.info("鉴定商品功能：参数={}",getIdentify);

        Integer i = identifyService.identifyTure(getIdentify.getIdentifyParam());
        if(i>0){
            return Result.success("已鉴定为"+getIdentify.getIdentifyParam().getIdentifyType());
        }
        return Result.fail("502","鉴定商品失败");
    }

    @PostMapping("identifyFalse")
    public Result identifyFalse(@RequestBody IdentifyParam identifyParam){
        log.info("鉴定商品为假货控制层");

        Integer i = identifyService.identifyFalse(identifyParam);
        if(i>0){
            return Result.success("已鉴定为假货");
        }
        return Result.fail("502","鉴定商品失败");
    }

    @PostMapping("identifyInvalid")
    public Result identifyInvalid(@RequestBody IdentifyParam identifyParam){
        log.info("资料不全，鉴定不了");

        Integer i = identifyService.identifyInvalid(identifyParam);
        if(i>0){
            return Result.success("资料不全，鉴定不了");
        }
        return Result.fail("502","鉴定商品失败");
    }
}

